package test;

import test.bean.UserBean;

import java.awt.*;

import javax.swing.*;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.util.ArrayList;

public class Store {

    JFrame frame;
    private JTextField textField;
    private UserBean user;

//    /**
//     * Launch the application.
//     */
//    public static void main(String[] args) {
//        EventQueue.invokeLater(new Runnable() {
//            public void run() {
//                try {
//                    Store window = new Store();
//                    window.frame.setVisible(true);
//                } catch (Exception e) {
//                    e.printStackTrace();
//                }
//            }
//        });
//    }

    /**
     * Create the application.
     */
    public Store() {
        initialize();
    }

    public Store(UserBean user) {
        this.user = user;
        initialize();
    }

    ;

    /**
     * Initialize the contents of the frame.
     */
    private void initialize() {
        frame = new JFrame();
        frame.setBounds(100, 100, 1200, 800);
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.getContentPane().setLayout(null);

        ArrayList tempPanelList = new ArrayList<JPanel>();

        JPanel ItemPanel = new JPanel();
        ItemPanel.setBounds(10, 116, 1166, 637);
        frame.getContentPane().add(ItemPanel);
        ItemPanel.setLayout(null);
        ItemPanel.hide();

        JPanel panel = new JPanel();
        panel.setBounds(10, 116, 1166, 637);
        frame.getContentPane().add(panel);
        panel.setLayout(null);

        ImageIcon[] images = {new ImageIcon("image/100.png"), new ImageIcon("image/101.png"), new ImageIcon("image/102.png")};
        final int[] i = {0};
        ImageIcon image1 = new ImageIcon("image/103.png");
        ImageIcon image2 = new ImageIcon("image/104.png");
        ImageIcon image3 = new ImageIcon("image/105.png");
        ImageIcon image4 = new ImageIcon("image/106.png");

        JPanel panel_2 = new JPanel();
        panel_2.setBounds(10, 10, 258, 617);
        panel.add(panel_2);
        panel_2.setLayout(new GridLayout(1, 0, 0, 0));

        JLabel lblNewLabel_7 = new JLabel(" 1");
        lblNewLabel_7.setFont(new Font("宋体", Font.PLAIN, 30));
        lblNewLabel_7.addMouseListener(new MouseAdapter() {
            @Override
            public void mouseClicked(MouseEvent e) {
                System.out.println(1);
            }
        });
        panel_2.add(lblNewLabel_7);

        JLabel lblNewLabel_4 = new JLabel(" 2");
        lblNewLabel_4.setFont(new Font("宋体", Font.PLAIN, 30));
        lblNewLabel_4.addMouseListener(new MouseAdapter() {
            @Override
            public void mouseClicked(MouseEvent e) {
                System.out.println(2);
            }
        });
        panel_2.add(lblNewLabel_4);

        JLabel lblNewLabel_8 = new JLabel(" 3");
        lblNewLabel_8.setFont(new Font("宋体", Font.PLAIN, 30));
        lblNewLabel_8.addMouseListener(new MouseAdapter() {
            @Override
            public void mouseClicked(MouseEvent e) {
                System.out.println(3);
            }
        });
        panel_2.add(lblNewLabel_8);

        JLabel lblNewLabel_6 = new JLabel(" 4");
        lblNewLabel_6.setFont(new Font("宋体", Font.PLAIN, 30));
        lblNewLabel_6.addMouseListener(new MouseAdapter() {
            @Override
            public void mouseClicked(MouseEvent e) {
                System.out.println(4);
            }
        });
        panel_2.add(lblNewLabel_6);

        JButton btnNewButton_7 = new JButton("New button");
        btnNewButton_7.setBounds(290, 291, 187, 336);
        btnNewButton_7.setIcon(image1);
        btnNewButton_7.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                System.out.println(1);
                panel.hide();
                reprintPaneltoItem(ItemPanel);
                ItemPanel.show();
            }
        });
        panel.add(btnNewButton_7);

        JButton btnNewButton_7_1 = new JButton("New button");
        btnNewButton_7_1.setBounds(512, 291, 187, 336);
        btnNewButton_7_1.setIcon(image2);
        btnNewButton_7_1.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                System.out.println(1);
                System.out.println(1);
                panel.hide();
                reprintPaneltoItem(ItemPanel);
                ItemPanel.show();
            }
        });
        panel.add(btnNewButton_7_1);

        JButton btnNewButton_7_2 = new JButton("New button");
        btnNewButton_7_2.setBounds(736, 291, 187, 336);
        btnNewButton_7_2.setIcon(image3);
        btnNewButton_7_2.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                System.out.println(1);
                System.out.println(1);
                panel.hide();
                reprintPaneltoItem(ItemPanel);
                ItemPanel.show();
            }
        });
        panel.add(btnNewButton_7_2);

        JButton btnNewButton_7_3 = new JButton("New button");
        btnNewButton_7_3.setBounds(969, 291, 187, 336);
        btnNewButton_7_3.setIcon(image4);
        btnNewButton_7_3.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                System.out.println(1);
                System.out.println(1);
                panel.hide();
                reprintPaneltoItem(ItemPanel);
                ItemPanel.show();
            }
        });
        panel.add(btnNewButton_7_3);

        JPanel panel_3 = new JPanel();
        panel_3.setBounds(290, 10, 866, 234);
        panel.add(panel_3);
        panel_3.setLayout(new BorderLayout(0, 0));

        JButton btnNewButton_6 = new JButton("下一个");

        panel_3.add(btnNewButton_6, BorderLayout.EAST);

        JButton btnNewButton_5 = new JButton("上一个");

        panel_3.add(btnNewButton_5, BorderLayout.WEST);

        JLabel lblNewLabel = new JLabel("New label");
        lblNewLabel.setIcon(images[0]);
        Timer timer = new Timer(2500, new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                if (i[0] > 2) {
                    i[0] = 0;
                } else if (i[0] < 0) {
                    i[0] = images.length - 1;
                }
                lblNewLabel.setIcon(images[i[0]]);
                i[0]++;
            }
        });
        timer.start();

        btnNewButton_5.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                i[0]--;
                if (i[0] < 0) {
                    i[0] = 2;
                }
                lblNewLabel.setIcon(images[i[0]]);
            }
        });

        btnNewButton_6.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                i[0]++;
                if (i[0] > 2) {
                    i[0] = 0;
                }
                lblNewLabel.setIcon(images[i[0]]);
            }
        });

        lblNewLabel.addMouseListener(new MouseAdapter() {
            @Override
            public void mouseClicked(MouseEvent e) {
                System.out.println(1);
                panel.hide();
                reprintPaneltoItem(ItemPanel);
                ItemPanel.show();
            }
        });
        panel_3.add(lblNewLabel, BorderLayout.CENTER);

        JPanel panel_1 = new JPanel();
        panel_1.setBounds(10, 49, 1166, 60);
        frame.getContentPane().add(panel_1);
        panel_1.setLayout(new BoxLayout(panel_1, BoxLayout.X_AXIS));

        JButton btnNewButton = new JButton("返回");
        btnNewButton.setBackground(Color.WHITE);
        btnNewButton.setForeground(Color.BLACK);
        btnNewButton.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                ItemPanel.hide();
                panel.show();
            }
        });
        panel_1.add(btnNewButton);

        JButton btnNewButton_1 = new JButton("前进");
        panel_1.add(btnNewButton_1);

        //个人资料按钮
        JButton btnUserInfo = new JButton("个人资料");
        panel_1.add(btnUserInfo);
        btnUserInfo.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                //关闭当前
                frame.setVisible(false);
                //创建新的
                UserInfo userInfoFrame = new UserInfo(user);
                userInfoFrame.setVisible(true);
            }
        });

        JButton btnNewButton_3 = new JButton("库");
        btnNewButton_3.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                frame.setVisible(false);
                EventQueue.invokeLater(new Runnable() {
                    public void run() {
                        try {
                            wareHouse window = new wareHouse(user);
                            window.frame.setVisible(true);
                        } catch (Exception e) {
                            e.printStackTrace();
                        }
                    }
                });
            }
        });
        panel_1.add(btnNewButton_3);

        JButton btnNewButton_4 = new JButton(" 帮  助 ");
        btnNewButton_4.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                frame.setVisible(false);
                CommunityFrame communityFrame = new CommunityFrame(user);
                communityFrame.frame.setVisible(true);
            }
        });

        panel_1.add(btnNewButton_4);

        JPanel panel_4 = new JPanel();
        panel_1.add(panel_4);

        textField = new JTextField();
        textField.setColumns(10);

        JButton btnNewButton_8 = new JButton("搜索");
        GroupLayout gl_panel_4 = new GroupLayout(panel_4);
        gl_panel_4.setHorizontalGroup(
                gl_panel_4.createParallelGroup(GroupLayout.Alignment.LEADING)
                        .addGroup(GroupLayout.Alignment.TRAILING, gl_panel_4.createSequentialGroup()
                                .addContainerGap(624, Short.MAX_VALUE)
                                .addComponent(textField, GroupLayout.PREFERRED_SIZE, 154, GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(btnNewButton_8))
        );
        gl_panel_4.setVerticalGroup(
                gl_panel_4.createParallelGroup(GroupLayout.Alignment.LEADING)
                        .addGroup(gl_panel_4.createSequentialGroup()
                                .addGap(6)
                                .addGroup(gl_panel_4.createParallelGroup(GroupLayout.Alignment.BASELINE)
                                        .addComponent(btnNewButton_8)
                                        .addComponent(textField, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)))
        );
        panel_4.setLayout(gl_panel_4);
    }

    public static void reprintPaneltoItem(JPanel panel) {
        JLabel lblNewLabel = new JLabel("这应该是相应的游戏图片 图片图片图片图片图片图片图片图片图片");
        lblNewLabel.setBackground(Color.GREEN);
        lblNewLabel.setFont(new Font("宋体", Font.PLAIN, 30));
        lblNewLabel.setBounds(10, 10, 1146, 247);
        panel.add(lblNewLabel);

        JLabel lblNewLabel_1 = new JLabel("这里应该是价格");
        lblNewLabel_1.setBackground(Color.GREEN);
        lblNewLabel_1.setFont(new Font("宋体", Font.PLAIN, 32));
        lblNewLabel_1.setBounds(10, 296, 476, 140);
        panel.add(lblNewLabel_1);

        JButton btnNewButton = new JButton("购买");
        btnNewButton.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                JOptionPane.showMessageDialog(null, "感谢您的购买");
            }
        });
        btnNewButton.setBounds(328, 348, 113, 36);
        panel.add(btnNewButton);

        JButton btnNewButton_1 = new JButton("下一张");
        btnNewButton_1.setBounds(1059, 10, 97, 247);
        panel.add(btnNewButton_1);
    }

    public static void backToStore(JPanel panel) {

    }
}
